package jp.idahopotato.calc;

import java.util.ArrayList;
import java.util.List;

import jp.idahopotato.activity.CreateProductHelper;
import jp.idahopotato.bean.Skill;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
import android.util.Log;

/**
 *
 * @author hiroki
 *
 */
public class Search extends SearchBase {
//	private static final String FILE_NAME = "PreferenceSkillSetFile";
	CreateProductHelper helper = null;
	SQLiteDatabase db = null;
	@Override
	void search() {
		// TODO 自動生成されたメソッド・スタブ

	}

	@Override
	void init() {
		// TODO 自動生成されたメソッド・スタブ
//		final SharedPreferences pref = getSharedPreferences(FILE_NAME, MODE_PRIVATE);

		helper = new CreateProductHelper(Search.this);
		try{
			//データベースを開く
			db = helper.getReadableDatabase();

			//各グループのスキル名の取得と、子リストの表示
			String columns[] = {"on_skill_id", "on_skill_name", "skill_description", "skill_point"};
			Cursor cursor;
			//アダプタ登録用全リスト
			List<Skill> list = new ArrayList<Skill>();
			SQLiteQueryBuilder build = new SQLiteQueryBuilder();
			build.setTables("t_on_skill LEFT JOIN m_skill ON(t_on_skill.skill_id = m_skill.skill_id)"
					+ "LEFT JOIN m_skill_group ON(m_skill.skill_group_id = m_skill_group.skill_group_id)");
			String where = "t_on_skill.on_skill_id = ?";
			for(int i=0; i<3; i++) {
				//検索条件は発動スキルID
				String[] param = {""};
				String sql = build.buildQuery(columns, where, param, null, null, "on_skill_id ASC", null);
				cursor = db.rawQuery(sql, param);

				if(cursor.moveToFirst()){
					Skill skill = new Skill();
					skill.setOnSkillId(cursor.getString(0));
					skill.setOnSkillName(cursor.getString(1));
					skill.setDetail(cursor.getString(2));
					skill.setPoint(cursor.getString(3));
					list.add(skill);
				}
			}
//			SkillSetAdapter adapter = new SkillSetAdapter(getApplicationContext(), list);

		} catch(Exception e){
			Log.e("ERROR", e.toString());
		}
		db.close();
	}

}
